package com.example.demo.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.demo.api.UserService;
import com.example.demo.util.ResMesg;
import com.example.demo.vo.UserVo;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * Created by Hy on 2018/3/30.
 */
@RestController
@RequestMapping("/user")
public class UserController extends BaseController{
    @Reference
    private UserService userService;

    @RequestMapping("/index")
    public String index(){
        return "index";
    }
    @RequestMapping("/findAll")
    public ResMesg getAllUsers(){
        List<UserVo> list = userService.getAllUsers();
        return sendTABLEJSON(list.size(), list);
    }
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public UserVo findOneById(@PathVariable("id")Integer id){
        if(id == null){
            id = 18;
        }
        System.out.println(id);
        UserVo user = userService.findOneById(id);
        if(user == null){
            user = new UserVo();
        }
        System.out.println(user);
        return user;
    }

    @RequestMapping("/saveOne")
    @ResponseBody
    public int saveOne(UserVo user){
        return userService.insertOne(user);
    }

    @RequestMapping("/delOne")
    @ResponseBody
    public int delOne(Integer id){
        return userService.delById(id);
    }

}
